#!/usr/bin/env ruby

ENV["RAILS_ENV"] ||= "production"

require File.dirname(__FILE__) + "/../../config/environment"

$running = true
Signal.trap("TERM") do 
  $running = false
end

while($running) do
  ActiveRecord::Base.logger.info "This daemon is still running at #{Time.now}.\n"
  
  Milestone.pending.reminder_not_sent.all(:conditions => ["due > ?", Date.today-48.hours]).each do |milestone|
    MilestoneMailer.deliver_reminder_email(milestone)
  end
  
  sleep 86400
end